﻿using System;
using System.Data;
using System.Text;

namespace ltModel.DAL
{
    /// <summary>
    /// 数据访问类loginlog。
    /// </summary>
    public class loginlog
    {
        public loginlog()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from lt_loginlog where id=" + id + "");
            return DataObject.Exists(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ltModel.Model.loginlog model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into lt_loginlog(");
            strSql.Append("username,ip,dat,type,zt,txt");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + model.username + "',");
            strSql.Append("'" + model.ip + "',");
            strSql.Append("'" + model.dat + "',");
            strSql.Append("'" + model.type + "',");
            strSql.Append("'" + model.zt + "',");
            strSql.Append("'" + model.txt + "'");
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            object obj = DataObject.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(ltModel.Model.loginlog model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update lt_loginlog set ");
            strSql.Append("username='" + model.username + "',");
            strSql.Append("ip='" + model.ip + "',");
            strSql.Append("dat='" + model.dat + "',");
            strSql.Append("zt='" + model.zt + "',");
            strSql.Append("txt='" + model.txt + "'");
            strSql.Append(" where id=" + model.id + "");
            DataObject.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete lt_loginlog ");
            strSql.Append(" where id=" + id);
            DataObject.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 按条件删除数据
        /// </summary>
        /// <param name="strWhere">条件</param>
        public void Delete(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete lt_loginlog ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            DataObject.ExecuteSql(strSql.ToString());
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ltModel.Model.loginlog GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append(" [id],[username],[ip],[dat],[type],[zt],[txt] ");
            strSql.Append(" from lt_loginlog ");
            strSql.Append(" where id=" + id);
            ltModel.Model.loginlog model = new ltModel.Model.loginlog();
            DataSet ds = DataObject.Query(strSql.ToString());
            model.id = id;
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.username = ds.Tables[0].Rows[0]["username"].ToString();
                model.ip = ds.Tables[0].Rows[0]["ip"].ToString();
                model.dat = ds.Tables[0].Rows[0]["dat"].ToString();
                model.type = ds.Tables[0].Rows[0]["type"].ToString();
                model.zt = ds.Tables[0].Rows[0]["zt"].ToString();
                model.txt = ds.Tables[0].Rows[0]["txt"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [id],[username],[ip],[dat],[type],[zt],[txt] ");
            strSql.Append(" FROM lt_loginlog ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DataObject.Query(strSql.ToString());
        }


        #endregion  成员方法
    }
}